#include"smodule.h"
#include"logger_rte.h"

int smodule::try_run(u32 tick) {
    {
#ifdef USE_EXCEPTION

        try
        {
#endif
        return run(tick);
#ifdef USE_EXCEPTION
        }
        catch (const std::exception &e)
        {
            logger.error(e.what());
//            core_debug(e.what());
        }
#endif
    }
    return -1;
}

smodule::smodule(const char *iname) : name(iname) {

}

int smodule::loop() {
    int res = -1;
    switch (state) {
        case 0:
            res = begin(rtos::ticks());
            if (!res)state = 1;
            break;
        default:
        case 1:
            res = diag(rtos::ticks());
            if (!res)state = 2;
            break;
        case 2:
            res = run(rtos::ticks());
            break;
    }
    return res;
}
